/*
 * console.h
 *
 *  Created on: 2016-10-28
 *      Author: m
 */

#ifndef SRC_INCLUDE_KERNEL_TTY_CONSOLE_H_
#define SRC_INCLUDE_KERNEL_TTY_CONSOLE_H_
#include "type.h"
#include "proc.h"

#define V_MEM_SIZE          (0x8000) //32K [0xB8000, 0xBFFFF]
#define V_MEM_BASE          (0xB8000)

#define SCROLL_TEXT_UP      (0)
#define SCROLL_TEXT_DOWN    (1)

typedef struct _console {
    int   cur_start_addr;   //相对于基址0xB8000的offset，操作单位:byte
    int   orig_addr;        //相对于基址0xB8000的offset，操作单位:byte
    int   v_mem_limit;      //单位：字节
    int   cursor;           //相对于基址0xB8000的offset，操作单位:byte,用法上同char*
} CONSOLE;

void init_console(CONSOLE* con, u32 v_mem_base, u32 v_mem_limit);
int console_set_cursor(u32 cursor);
int console_out_char(CONSOLE* con, char c);
void console_set_start_addr(u16 start_addr);
void console_on_key_evnet(CONSOLE* con, u8 xkey);
void console_scroll(CONSOLE* con, int direction, int row);
int console_clean_screen(CONSOLE* con);
int console_on_enter();
int write_impl(int fd, void* buf, int count, PROCESS* requre_proc);

#endif /* SRC_INCLUDE_KERNEL_TTY_CONSOLE_H_ */
